package com.example.anql.service.impl;

import com.example.anql.common.ReturnObject;
import com.example.anql.common.ReturnUtil;
import com.example.anql.entity.Shop;
import com.example.anql.dao.ShopDao;
import com.example.anql.service.ShopService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Shop)表服务实现类
 *
 * @author makejava
 * @since 2022-12-10 12:46:03
 */
@Service("shopService")
public class ShopServiceImpl implements ShopService {
    @Resource
    private ShopDao shopDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Shop queryById(Integer id) {
        return this.shopDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param shop 筛选条件
     * @return 查询结果
     */
    @Override
    public ReturnObject queryByPage(Shop shop ) {
        PageHelper.startPage(shop.getPage(),shop.getSize());
        List<Shop> listShop = shopDao.queryByPage(shop);
        PageInfo<Shop> pageInfo = new PageInfo<>(listShop);

        return ReturnUtil.success(pageInfo);
    }

    /**
     * 新增数据
     *
     * @param shop 实例对象
     * @return 实例对象
     */
    @Override
    public Shop insert(Shop shop) {

        this.shopDao.insert(shop);
        shopDao.insert_get_shop(shop);
        return shop;
    }

    /**
     * 修改数据
     *
     * @param shop 实例对象
     * @return 实例对象
     */
    @Override
    public Shop update(Shop shop) {
        this.shopDao.update(shop);
        return this.queryById(shop.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.shopDao.deleteById(id) > 0;
    }
}
